//
//  YWVideoVideoTopic.m
//
//  Created by Yeewii@hotmail com on 16/6/16
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "YWVideoVideoTopic.h"


NSString *const kYWVideoVideoTopicTname = @"tname";
NSString *const kYWVideoVideoTopicAlias = @"alias";
NSString *const kYWVideoVideoTopicTid = @"tid";
NSString *const kYWVideoVideoTopicEname = @"ename";


@interface YWVideoVideoTopic ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation YWVideoVideoTopic

@synthesize tname = _tname;
@synthesize alias = _alias;
@synthesize tid = _tid;
@synthesize ename = _ename;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.tname = [self objectOrNilForKey:kYWVideoVideoTopicTname fromDictionary:dict];
            self.alias = [self objectOrNilForKey:kYWVideoVideoTopicAlias fromDictionary:dict];
            self.tid = [self objectOrNilForKey:kYWVideoVideoTopicTid fromDictionary:dict];
            self.ename = [self objectOrNilForKey:kYWVideoVideoTopicEname fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.tname forKey:kYWVideoVideoTopicTname];
    [mutableDict setValue:self.alias forKey:kYWVideoVideoTopicAlias];
    [mutableDict setValue:self.tid forKey:kYWVideoVideoTopicTid];
    [mutableDict setValue:self.ename forKey:kYWVideoVideoTopicEname];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.tname = [aDecoder decodeObjectForKey:kYWVideoVideoTopicTname];
    self.alias = [aDecoder decodeObjectForKey:kYWVideoVideoTopicAlias];
    self.tid = [aDecoder decodeObjectForKey:kYWVideoVideoTopicTid];
    self.ename = [aDecoder decodeObjectForKey:kYWVideoVideoTopicEname];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_tname forKey:kYWVideoVideoTopicTname];
    [aCoder encodeObject:_alias forKey:kYWVideoVideoTopicAlias];
    [aCoder encodeObject:_tid forKey:kYWVideoVideoTopicTid];
    [aCoder encodeObject:_ename forKey:kYWVideoVideoTopicEname];
}

- (id)copyWithZone:(NSZone *)zone
{
    YWVideoVideoTopic *copy = [[YWVideoVideoTopic alloc] init];
    
    if (copy) {

        copy.tname = [self.tname copyWithZone:zone];
        copy.alias = [self.alias copyWithZone:zone];
        copy.tid = [self.tid copyWithZone:zone];
        copy.ename = [self.ename copyWithZone:zone];
    }
    
    return copy;
}


@end
